import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Random;

public class Test {

    public static void inorderArray(int[] array){
        //有序情况下
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    public static void notInorderArray(int[] array){
        //无序情况下
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length-i;
        }
    }

    public static  void initArray(int[] array){
        Random random = new Random();
        //随机的
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(array.length);
        }
    }

    //测试排序
    public static void TestInsertSort(int[] array){
        int[] testArray = Arrays.copyOf(array,2*array.length);
        long startTime = System.currentTimeMillis();//获取当前时间(毫秒)
        Sort.insertSort(testArray);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序的时间是:"+(endTime-startTime));
    }

    public static void TestSelectSort(int[] array) {
        int[] testArray = Arrays.copyOf(array, 2 * array.length);
        long startTime = System.currentTimeMillis();//获取当前时间(毫秒)
        Sort.selectSort(testArray);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序的时间是:" + (endTime - startTime));
    }

    public static void TestShellSort(int[] array) {
        int[] testArray = Arrays.copyOf(array, 2 * array.length);
        long startTime = System.currentTimeMillis();//获取当前时间(毫秒)
        Sort.ShellSort(testArray);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序的时间是:" + (endTime - startTime));
    }

    public static void main1(String[] args){
        int[] array = new int[10000];
        //inorderArray(array);
        //notInorderArray(array);
        initArray(array);

        TestInsertSort(array);
        TestSelectSort(array);
        TestShellSort(array);
    }

    public static void main(String[] args) {
        int[] array = {3,6,1,8,4};
        Sort.insertSort(array);
        System.out.println(Arrays.toString(array));

        int[] array1={3,7,1,8,9,2};
        Sort.selectSort(array1);
        System.out.println(Arrays.toString(array1));

        int[] array3={3,7,1,8,9,2};
        Sort.selectSort3(array3);
        System.out.println(Arrays.toString(array3));

        int[] array2={3,7,1,8,9,2};
        Sort.heapSort(array2);
        System.out.println(Arrays.toString(array2));
    }
}
